package com.leetcode.LC;

import java.util.Arrays;

public class LC628 {
    public int maximumProduct(int[] nums) {

        int sum = 1;
        if (nums.length == 3) {
            for (int num : nums) {
                sum *= num;
            }
            return sum;
        }
        Arrays.sort(nums);
        if (nums[0] < 0 && nums[1] < 0) {
            return Math.max(nums[0] * nums[1] * nums[nums.length - 1], nums[nums.length - 3] * nums[nums.length - 2] * nums[nums.length - 1]);
        }
        return nums[nums.length - 3] * nums[nums.length - 2] * nums[nums.length - 1];
    }

    public static void main(String[] args) {
        System.out.println(new LC628().maximumProduct(new int[]{-1, -2, 3, 4}));
    }
}
